pub fn min_edge_prime_num(number: u32) -> String {
    let prime_vec = sieve_of_eratosthenes(10_000_000); // 预先生成素数表
    for n in 1..u32::MAX - 1 {
        let (vec, size) = out_put(n);
        let num_count = vec.len();
        let prime_count = count_prime(&vec, &prime_vec);
        if prime_count == 0 {
            continue;
        }
        //
        let ratio = (prime_count as f64 / num_count as f64) * 100.0;
        let ratio = format!("{:.2}", ratio).parse::<f64>().unwrap();
        if ratio < number as f64 {
            // println!("ratio:{},number:{}", ratio, number);
            return format!("{},{}", size, prime_count);
        }
    }

    unreachable!()
}

// 输入半边长，返回对角线数组和边长
fn out_put(side: u32) -> (Vec<u32>, u32) {
    let mut res = vec![];
    let mut start = 1;
    res.push(start);
    if side == 1 {
        return (res, 1);
    }
    for i in 1..side {
        start += 8 * i - 6;
        res.push(start);
        let count_outside = 2 * i;
        for j in 1..4 {
            let num = start + count_outside * j;
            res.push(num);
        }
    }
    (res, 2 * side - 1)
}

fn count_prime(vec: &Vec<u32>, prime_vec: &Vec<bool>) -> usize {
    vec.iter()
        .filter(|&&x| prime_vec.get(x as usize).copied().unwrap_or(false))
        .count()
}

// 使用埃拉托斯特尼筛法生成素数表
fn sieve_of_eratosthenes(limit: usize) -> Vec<bool> {
    let mut is_prime = vec![true; limit + 1];
    is_prime[0] = false; // 0 不是素数
    is_prime[1] = false; // 1 不是素数

    // 从2开始，到 limit 进行筛选
    for i in 2..=(limit as f64).sqrt() as usize {
        if is_prime[i] {
            // 从 i * i 开始标记倍数
            let mut multiple = i * i;
            while multiple <= limit {
                is_prime[multiple] = false;
                multiple += i;
            }
        }
    }

    is_prime
}
